#ifndef PORTTYPE_H
#define PORTTYPE_H
#include "porttestdll_global.h"
#include <QObject>
#include <QtXml/QDomDocument>
#include <QVector>
#include <QTime>
#include <QCoreApplication>
#include "IoInfor.h"
#include "delete.h"
#include "TestResult.h"

class CPortType : public QObject{
public:
	CPortType(CTestResult &testResultTemp)
		:testResult(testResultTemp),
		 //m_port(NULL),
		 timeout(UINT_MAX){
	}
	virtual ~CPortType(void){
		DelObj(m_io);
		//delete m_port;
		//m_port = NULL;
	}
private:
	CPortType(void);
public:
    virtual QBool		SetIOs(QDomElement &ios)	=0;
    virtual QBool		RunTest()					=0;
    virtual EProtocol	GetEProtocol()				=0;
	//virtual QBool		writeIoVector();
	//virtual void		onReadyRead();
	//virtual QBool		writeIoVectorTcp();
	//virtual void		onReadyReadTcp();
	//virtual QBool		writeIoVectorUdp();
	//virtual void		onReadyReadUdp();
public:
	void waitForReadyRead(quint32 tt);
protected:
	//QIODevice			*m_port;
    quint32				timeout;
	QVector<CIoInfor*>	m_io;
	qint32				io_index;
	
	CTestResult			&testResult;
};

//
#define GetIntAttribute(dom, x)	if(dom.hasAttribute(#x)){\
									x = dom.attribute(#x).toInt();\
								}
#define GetStrAttribute(dom, x)	if(dom.hasAttribute(#x)){\
									x = dom.attribute(#x);\
								}
#endif //PORTTYPE_H
